package semspe;
import javax.swing.*;
import java.awt.event.*;

class SuppStock extends JFrame implements ActionListener//implements WindowListener
{
	private JPanel panel;
	private JLabel stock;
	
	
	private JComboBox txtStock;

	
	private JOptionPane jop1;
	private JButton OK;
	private JButton annuler;
	
	public SuppStock()
	{
		super("Supprimer un stock");
		this.setSize(400,600);
		this.setResizable(false);
		this.setVisible(true);
		
		this.getContentPane().setLayout(null);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		this.panel = new JPanel();
		
		
		//Stock
		this.stock = new JLabel("Stock :");
		this.getContentPane().add(this.stock);
		this.stock.setBounds(30,220,150,20);
		this.txtStock = new JComboBox();
		this.getContentPane().add(this.txtStock);
		this.txtStock.setBounds(200,220,150,20);
                TraitRequete ligneStock = new TraitRequete();
                String [] resultatVouluLigneStock = new String[]{"Count(libelleStock)"};
                String [][] resRecupLigneStock = ligneStock.ExecuteRequete("SELECT Count(libelleStock) FROM stock", resultatVouluLigneStock,1 );
                TraitRequete recupStocks = new TraitRequete();
                String [] resultatVouluStock = new String[]{"libelleStock"};
                String [][] resRecupStocks = recupStocks.ExecuteRequete("SELECT libelleStock FROM stock;", resultatVouluStock, Integer.parseInt(resRecupLigneStock[0][0]));
                int i=0;
                for(i=0; i<resRecupStocks[0].length;i++)
                {
                  txtStock.addItem(resRecupStocks[0][i]);  
                }
		
		
		
				
		
		
		//BUT
		this.OK = new JButton("Ajouter");
		this.getContentPane().add(this.OK);
		this.OK.setBounds(100,400,100,20);
		this.annuler = new JButton("Annuler");
		this.getContentPane().add(this.annuler);
		this.annuler.setBounds(250,400,100,20);
		
		this.annuler.addActionListener(this);
		this.OK.addActionListener(this);
		
		jop1 = new JOptionPane();
		
		
	}
	

	public void actionPerformed(ActionEvent evt) {
			if(evt.getSource() == annuler)
			this.dispose();
			else if(evt.getSource() == OK){
                            
			String requete = "DELETE FROM stock WHERE stock.libelleStock ='"+this.txtStock.getSelectedItem()+"'";
                           
                            
                           TraitRequete ajoutStock = new TraitRequete();
                            ajoutStock.ExecuteRequeteData(requete);
                            this.dispose();
                            
                        }
	}                
        
        
        
        
	
	public static void main (String[] a)
	{
		SuppStock stocasupp1 = new SuppStock();
	}
	
} 
